package com.segment.ranking.service;

import java.util.List;

import com.segment.ranking.dao.RankingDAO;
import com.segment.ranking.vo.RankingVO;

public class RankingService {
	private RankingDAO dao = new RankingDAO();
	
	public List<RankingVO> test(RankingVO vo){
		return this.dao.test(vo);
	}
	
	public List<RankingVO> getRanking(String userCode){
		return this.dao.getRanking(userCode);
	}
	
	public List<RankingVO> createUserCode(){
		List<RankingVO> list = this.dao.getNewUserCode();

		this.dao.insertUserCode(list.get(0));
		
		return list;
	}
	
	public List<RankingVO> access(String userCode){
		List<RankingVO> list = this.dao.checkUser(userCode);

		if(list.size() != 0)
			this.dao.updateFilnalAccessDate(list.get(0).getUserCode());
		
		return list;
	}
	
	public List<RankingVO> registerScore(RankingVO vo){
		List<RankingVO> list = this.dao.getScore(vo);
		
		int rtn = 0;
		
		if(list.size() > 0){
			if(vo.getScore() > list.get(0).getScore()){
				this.dao.updateScore(vo);
			}
			
		}else{
			this.dao.insertScore(vo);
		}

		return list;
	}
}
